
$.wait = function(time) {
  return $.Deferred(function(dfd) {
    setTimeout(dfd.resolve, time);
  });
}

var data = [];

function get_matrix()
{
   

data.push({"x":5,"y":90,"date":"2012-01-01","r":20});
data.push({"x":25,"y":30,"date":"2013-02-02","r":30});
data.push({"x":45,"y":50,"date":"2013-03-03","r":20});
data.push({"x":65,"y":55,"date":"2013-04-04","r":10});
data.push({"x":85,"y":20,"date":"2013-05-05","r":8});

var margin = {top: 20, right: 20, bottom: 30, left: 40},
    width = 960 - margin.left - margin.right,
    height = 500 - margin.top - margin.bottom;

var x = d3.scale.linear()
    .domain([0, width / 2])
    .range([0, width]);

var r = d3.scale.linear()
    .domain([0, width / 2])
    .range([0, width]);

var y = d3.scale.linear()
    .domain([0, 100])
    .range([height, 0]);

var xAxis = d3.svg.axis()
    .scale(x)
    .orient("bottom")
    .tickSize(6);

var yAxis = d3.svg.axis()
    .scale(y)
    .orient("left")
    .ticks(5);

var zoom = d3.behavior.zoom()
    .x(x)
    .scaleExtent([1, 10])
    .on("zoom", zoomed);

var svg = d3.select(".target_matrix_body").append("svg")
    .attr("width", width + margin.left + margin.right)
    .attr("height", height + margin.top + margin.bottom)
  .append("g")
    .attr("transform", "translate(" + margin.left + "," + margin.top + ")")
    .call(zoom);

svg.append("rect")
    .attr("width", width)
    .attr("height", height);

svg.append("g")
    .attr("class", "x axis")
    .attr("transform", "translate(0," + height + ")")
    .call(xAxis);

svg.append("g")
    .attr("class", "y axis")
    .call(yAxis);
    
svg.append("circle")
    .data(data)
    .attr("r", "10")
    .attr("cy", "10")
    .attr("cx", "10")
    .attr("fill", "#fff");
    
svg.append("circle")
    .data(data)
    .attr("r", "10")
    .attr("cy", "50")
    .attr("cx", "50")
    .attr("fill", "#fff");

d3.select("button").on("click", reset);

var k=2;

function zoomed() {
  svg.select(".x.axis").call(xAxis);
  svg.select(".y.axis").call(yAxis);
  
  var kk=d3.event.scale;
  var kk1=d3.event.translate;
  svg.selectAll("circle").attr('cx',kk1[0]);
}

function reset() {
  d3.transition().duration(750).tween("zoom", function() {
    var ix = d3.interpolate(x.domain(), [0, width / 2]),
        iy = d3.interpolate(y.domain(), [0, 100]);
    return function(t) {
      zoom.x(x.domain(ix(t))).y(y.domain(iy(t)));
      zoomed();
    };
  });
}

}

$(document).ready(function()
{
    $('.navbar').addClass('noview');
    $('.main_info_head').addClass('noview');
    
    $('body').addClass('target_matrix');
    
    
    get_matrix();
    
    
    
});
